<template>
  <el-dialog
    title="新增"
    :model-value="addVisible"
    width="30%"
    :before-close="close"
    append-to-body
  >
    <el-form ref="formref" :model="form">
      <el-form-item label="姓名" label-width="80px" prop="userName">
        <el-input v-model="form.userName" autocomplete="off" />
      </el-form-item>
      <el-form-item label="账号" label-width="80px" prop="account">
        <el-input v-model="form.account" autocomplete="off" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="handleAddSubmit">保存</el-button>
        <el-button @click="handleAddClose">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup name="Add">
const { proxy } = getCurrentInstance();
const addVisible = ref(false);
const emit = defineEmits(['handleAddSubmit']);

const form = reactive({
  userName: '',
  account: ''
})

// 显示弹框
function show() {
  addVisible.value = true;
}

// 取消
function handleAddClose() {
  addVisible.value = false;
  proxy.resetForm("formref");
}

// 提交
function handleAddSubmit() {
  emit('handleAddSubmit', form)
  proxy.resetForm("formref");
}

// 关闭弹框
function close() {
  addVisible.value = false;
  proxy.resetForm("formref");
}

// 暴露给父组件使用的方法
defineExpose({
  show,
  close
});
</script>

<style scoped>

</style>
